package pig.model;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
@Service
public class SellerServiceImpl  implements CommonService {
	
	@Resource(name="commonDAOImpl")
	private CommonDAO commonDAO;	
	
	//QNAList가져오기
	@Override
	public ListVO getQNAList(String pageNo,String dealNumber) {
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		
		List<BoardVO> list=commonDAO.getQNAList(pageNo,dealNumber);
		int total=commonDAO.totalContentByDeal(dealNumber);
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));

		return new ListVO(list,paging);
	}

	// QNA 글쓰기
	@Override
	public void write(BoardVO bvo) {
		commonDAO.write(bvo);
	}

	// 조회수 미증가
	@Override
	public BoardVO showContentNoHit(int no) {
		return commonDAO.showContent(no);
	}

	// 게시물 상세보기
	@Override
	public BoardVO showContent(int no) {
		commonDAO.updateCount(no);
		return commonDAO.showContent(no);
	}

	//답글 작성
	@Override
	public void replyWrite(BoardVO bvo) {
		  int ref = bvo.getRef();
		  int restep = bvo.getRestep();
		  int relevel = bvo.getrelevel();
		  commonDAO.updateRestep(ref, restep);
		  bvo.setRestep(restep+1);
		  bvo.setrelevel(relevel+1);
		  commonDAO.replyWrite(bvo);//답변 글 입력
	}

	// 글 삭제
	@Override
	public void deleteBoard(String no) {
		commonDAO.deleteBoard(no);
	}

	// 글 수정
	@Override
	public void updateBoard(BoardVO bvo) {
		commonDAO.updateBoard(bvo);
	}
	
	//쪽지함 전체보기
	@Override
	public ListVO postShowSendList(String pageNo,String id, String auth,String post) {
		ArrayList<PostBoxVO> list=new ArrayList<PostBoxVO>();
    	PagingBean paging = null;
    	if(pageNo==null||pageNo=="") 
			pageNo="1";
    	if(post.equals("send")){
    		list=(ArrayList<PostBoxVO>) commonDAO.postShowSendList(pageNo,id,auth);
    		int sendTotal=commonDAO.sendPostTotal(id, auth);
    		paging=new PagingBean(sendTotal,Integer.parseInt(pageNo));
    	}else{
    		list=(ArrayList<PostBoxVO>) commonDAO.postShowReceiveList(pageNo,id,auth);
    		int receiveTotal=commonDAO.receiverPostTotal(id, auth);
    		paging=new PagingBean(receiveTotal,Integer.parseInt(pageNo));
    	}
			return new ListVO(list,paging);
	}
}
